package com.jx.smartbot.entityListener;

import javax.annotation.Resource;
import javax.persistence.PostPersist;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

import com.jx.smartbot.VO.GoComMessage4Text;
import com.jx.smartbot.entity.WpRemind;
import com.jx.smartbot.service.SystemSuperApp;

public class WpRemindListener {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(WpRemindListener.class);
	@Autowired
	RestTemplate restTemplate;
	@Autowired
	SystemSuperApp systemSuperApp;
	@Resource(name="defaultAppId")
	String defaultAppId;
	
	@Resource(name="apiurl")
	String gocomeApiUrl;
	
	@PostPersist
    public void postPersist(Object entity) {
		if (entity.getClass() !=WpRemind.class){
			return;
		}
		WpRemind wpRemind=(WpRemind)entity;
		String appid=systemSuperApp.appid_token(defaultAppId);
		String rt = restTemplate.postForObject(gocomeApiUrl + "message/single/send/status?"+appid,takeGoComMessage4Text(wpRemind),String.class);
	}
	private GoComMessage4Text takeGoComMessage4Text(WpRemind remind){
		GoComMessage4Text gtext = new GoComMessage4Text();
		gtext.setTouser("");
		return gtext;
	}
}
